package com.feiwo.nonego.rpc.protocol.header;

import java.io.Serial;
import java.io.Serializable;

/**
 * RPC 消息头
 *  +---------------------------------------------------------------+
 *  | 魔数 2byte | 报文类型 1byte | 状态 1byte | 消息 ID 8byte |
 *  +---------------------------------------------------------------+
 *  | 序列化类型 16byte | 数据长度 4byte |
 *  +---------------------------------------------------------------+
 *
 * @author feiwo 2025-08-05
 */
public class RpcHeader implements Serializable {

    @Serial
    private static final long serialVersionUID = 4394097569900415530L;

    /**
     * 魔数 2字节
     */
    private short magic;

    /**
     * 消息类型 1字节
     */
    private byte msgType;

    /**
     * 状态 1字节
     */
    private byte status;

    /**
     * 消息id 8字节
     */
    private long msgId;

    /**
     * 序列化类型16字节，不足16字节后面补0，约定序列化类型长度最多不能超过16
     */
    private String serializationType;

    /**
     * 消息长度 4字节
     */
    private int msgLen;

    public short getMagic() {
        return magic;
    }

    public void setMagic(short magic) {
        this.magic = magic;
    }

    public byte getMsgType() {
        return msgType;
    }

    public void setMsgType(byte msgType) {
        this.msgType = msgType;
    }

    public byte getStatus() {
        return status;
    }

    public void setStatus(byte status) {
        this.status = status;
    }

    public long getMsgId() {
        return msgId;
    }

    public void setMsgId(long msgId) {
        this.msgId = msgId;
    }

    public String getSerializationType() {
        return serializationType;
    }

    public void setSerializationType(String serializationType) {
        this.serializationType = serializationType;
    }

    public int getMsgLen() {
        return msgLen;
    }

    public void setMsgLen(int msgLen) {
        this.msgLen = msgLen;
    }

    @Override
    public String toString() {
        return "RpcHeader{" +
                "magic=" + magic +
                ", msgType=" + msgType +
                ", status=" + status +
                ", msgId=" + msgId +
                ", serializationType='" + serializationType + '\'' +
                ", msgLen=" + msgLen +
                '}';
    }
}
